package codename.carrot.bomberman.models;

import codename.carrot.bomberman.BitmapFactory;
import codename.carrot.bomberman.game.listener.ObstacleListener;

/**
 *  A class representing a flame
 *  
 * @author Group A4
 *
 */

public class Flame extends AbstractAnimatedObstacle {
	/**
	 *  The time of creation of this flame
	 */
    private long timeOfCreation = System.currentTimeMillis();
    /**
     *  The time it will take before it is visible
     */
    private int timeToVisible;
    /**
     *  The bomb that created this flame
     */
    private Bomb bomb;
    
    /**
     *  Constructor
     * @param xCoor the x-coordinate of this flame
     * @param yCoor the y-coordinate of this flame
     * @param bomb the bomb that created the flame
     * @param listener the listener of this flame
     * @param timeToVisible the time till the flame should be visible
     */
    public Flame(int xCoor, int yCoor, Bomb bomb ,ObstacleListener listener, int timeToVisible) {
    	super(xCoor, yCoor, BitmapFactory.buildExplotionView(), listener, false);
        this.timeToVisible = timeToVisible;
        this.bomb = bomb;
    }


    @Override
    public boolean isDestructible() {
        return false;
    }

    /**
     * Returns the bomb which crated this flame
     * @return bomb
     */
    public Bomb getBomb() {
        return bomb;
    }

    /**
     *  Updates the state of this flame based on number of miliseconds since last update
     */
    @Override
    public void update(float dt) {
        super.update(dt);
        if(System.currentTimeMillis() > timeOfCreation + timeToVisible){
        	setVisible(true);
        	fireObstacleVisibilityChanged();
        }
        // We want to remove this flame when it's animation has played once
        if(hasPlayedOnce) {
            fireRemoveObstacle();
        }
    }
}
